package com.heima.article.lisener;

import com.alibaba.fastjson.JSON;
import com.heima.article.entity.ArticleStreamMessage;
import com.heima.article.service.IComputeService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

@Service
public class ArticleResultLisener {
    @Autowired
    private IComputeService computeService;

    @KafkaListener(topics = "article_behavior")
    public void handleMessage(ConsumerRecord<String,String> record){
        String value = record.value();
        ArticleStreamMessage message = JSON.parseObject(value, ArticleStreamMessage.class);
        computeService.Update(message);
    }
}
